package com.example.blog.util;


import com.example.blog.base.CurrentAccount;
import com.example.blog.exception.BizAssertUtils;

/**
 * @Classname RequestUtils
 * @Description TODO
 * @Version 1.0.0
 * @Date 2023/8/17 22:39
 * @Created by wlh12
 */

public class CurrentUserUtils {
    private static ThreadLocal<CurrentAccount> threadLocal = new ThreadLocal<>();
    public static CurrentAccount currentUser() {
        CurrentAccount principal = threadLocal.get();;
        BizAssertUtils.notNull(principal,"未登录");
        return principal;
    }

    public static void setThreadLocal(CurrentAccount currentAccount) {
        threadLocal.set(currentAccount);
    }

    public static void clear() {
        threadLocal.remove();
    }
}
